package cn.wiseda.finance.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.wiseda.finance.dao.util.JdbcBasicDao;
import cn.wiseda.finance.entity.Store;

@Component
public class StoreDao extends JdbcBasicDao {

    public boolean saveStore(Store store) {
        String sql = "INSERT INTO t_store (room_code,address,type,buildingArea,useArea,decoration,price,status,remarks) VALUES(?,?,?,?,?,?,?,?,?)";
        int insert = getJdbc().update(sql, store.getRoomCode(), store.getAddress(), store.getType(),
                store.getBuildingArea(), store.getUseArea(), store.getDecoration(), store.getPrice(),
                store.getStatus(), store.getRemarks());
        return insert > 0 ? true : false;
    }

    public List<Store> queryStores() {
        String sql = "SELECT * FROM t_store";
        List<Store> stores = queryForBeans(sql, Store.class);
        return stores;
    }

    public Store queryStore(int id) {
        String sql = "SELECT * FROM t_store WHERE id=?";
        Store store = queryForBean(sql, Store.class, id);
        return store;
    }

    public boolean modifyStore(Store store) {
        String sql = "UPDATE t_store SET room_code=?,address=?,type=?,buildingArea=?,useArea=?,decoration=?,price=?,status=?,remarks=? WHERE id=?";
        int update = getJdbc().update(sql, store.getRoomCode(), store.getAddress(), store.getType(),
                store.getBuildingArea(), store.getUseArea(), store.getDecoration(), store.getPrice(),
                store.getStatus(), store.getRemarks(), store.getId());
        return update > 0 ? true : false;
    }

}
